 //获取账号，密码，表单节点
 let username = document.querySelector('input[name="username"]')
 let password = document.querySelector('input[name="password"]')
 let zc = document.querySelector('.zcbtn')
 let form = document.querySelector('form')
   //账号非空，格式判定，封装成函数
   function zh() {
    if (username.value == '') {
        username.nextElementSibling.innerText = '账号不能为空'
    } else {
        let reg = /^\d{9}$/
        if (reg.test(username.value) == true) {
            username.nextElementSibling.innerText = ''
            return 1 //验证成功返回一个值下面做判定是否提交
        } else {
            username.nextElementSibling.innerText = '账号由9位数字构成'
        }
    }
}
//账号失去焦点验证
username.onblur = function () {
    zh()
}
//密码非空，格式判定，封装成函数
function mima() {
    if (password.value == '') {
        password.nextElementSibling.innerText = '密码不能为空'
    } else {
        let reg = /^[a-z]\d{8}$/
        if (reg.test(password.value) == true) {
            password.nextElementSibling.innerText = ''
            return 1 //验证成功返回一个值下面做判定是否提交
        } else {
            password.nextElementSibling.innerText = '密码有一位小写字母8位数字构成'
        }

    }
}
//密码失去焦点验证
password.onblur = function () {
    mima()
}
//注册事件
zc.onclick = function (e) {

    zh()
    mima()
    e = e || window.event

    if (zh() == 1 && mima() == 1) {
        let name = username.value
        let mima = password.value
        let obj = {
            name: name,
            mima: mima
        }
        let str = localStorage.getItem('yonghu')
        let arr = JSON.parse(str) || []
        arr.push(obj)

        localStorage.setItem('yonghu', JSON.stringify(arr))
        alert('注册成功')
    }
    return false
}